package o;

import com.huawei.hms.framework.common.ContainerUtils;
import java.io.ObjectStreamException;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.AbstractSet;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;

public final class atz<K, V> extends AbstractMap<K, V> implements Serializable {
    static final /* synthetic */ boolean ॱॱ = (!atz.class.desiredAssertionStatus());
    private static final Comparator<Comparable> ᐝ = new Comparator<Comparable>() {
        public /* synthetic */ int compare(Object obj, Object obj2) {
            return ˎ((Comparable) obj, (Comparable) obj2);
        }

        public int ˎ(Comparable comparable, Comparable comparable2) {
            return comparable.compareTo(comparable2);
        }
    };
    private e ʻ;
    private c ʼ;
    d<K, V> ˊ;
    final d<K, V> ˋ;
    Comparator<? super K> ˎ;
    int ˏ;
    int ॱ;

    abstract class b<T> implements Iterator<T> {
        final /* synthetic */ atz ʽ;
        d<K, V> ˊ = this.ʽ.ˋ.ˎ;
        int ˎ = this.ʽ.ॱ;
        d<K, V> ˏ = null;

        b(atz o_atz) {
            this.ʽ = o_atz;
        }

        public final boolean hasNext() {
            return this.ˊ != this.ʽ.ˋ;
        }

        final d<K, V> ˋ() {
            d<K, V> dVar = this.ˊ;
            if (dVar == this.ʽ.ˋ) {
                throw new NoSuchElementException();
            } else if (this.ʽ.ॱ != this.ˎ) {
                throw new ConcurrentModificationException();
            } else {
                this.ˊ = dVar.ˎ;
                this.ˏ = dVar;
                return dVar;
            }
        }

        public final void remove() {
            if (this.ˏ == null) {
                throw new IllegalStateException();
            }
            this.ʽ.ˎ(this.ˏ, true);
            this.ˏ = null;
            this.ˎ = this.ʽ.ॱ;
        }
    }

    final class c extends AbstractSet<K> {
        final /* synthetic */ atz ˋ;

        c(atz o_atz) {
            this.ˋ = o_atz;
        }

        public int size() {
            return this.ˋ.ˏ;
        }

        public Iterator<K> iterator() {
            return new b<K>(this) {
                final /* synthetic */ c ˋ;

                {
                    this.ˋ = r2;
                    atz o_atz = r2.ˋ;
                }

                public K next() {
                    return ˋ().ʽ;
                }
            };
        }

        public boolean contains(Object obj) {
            return this.ˋ.containsKey(obj);
        }

        public boolean remove(Object obj) {
            return this.ˋ.ˏ(obj) != null;
        }

        public void clear() {
            this.ˋ.clear();
        }
    }

    static final class d<K, V> implements Entry<K, V> {
        V ʻ;
        final K ʽ;
        d<K, V> ˊ;
        d<K, V> ˋ;
        d<K, V> ˎ;
        d<K, V> ˏ;
        d<K, V> ॱ;
        int ॱॱ;

        d() {
            this.ʽ = null;
            this.ˋ = this;
            this.ˎ = this;
        }

        d(d<K, V> dVar, K k, d<K, V> dVar2, d<K, V> dVar3) {
            this.ˏ = dVar;
            this.ʽ = k;
            this.ॱॱ = 1;
            this.ˎ = dVar2;
            this.ˋ = dVar3;
            dVar3.ˎ = this;
            dVar2.ˋ = this;
        }

        public K getKey() {
            return this.ʽ;
        }

        public V getValue() {
            return this.ʻ;
        }

        public V setValue(V v) {
            V v2 = this.ʻ;
            this.ʻ = v;
            return v2;
        }

        public boolean equals(Object obj) {
            if (!(obj instanceof Entry)) {
                return false;
            }
            Entry entry = (Entry) obj;
            if (this.ʽ == null) {
                if (entry.getKey() != null) {
                    return false;
                }
            } else if (!this.ʽ.equals(entry.getKey())) {
                return false;
            }
            if (this.ʻ == null) {
                if (entry.getValue() != null) {
                    return false;
                }
            } else if (!this.ʻ.equals(entry.getValue())) {
                return false;
            }
            return true;
        }

        public int hashCode() {
            int i = 0;
            int hashCode = this.ʽ == null ? 0 : this.ʽ.hashCode();
            if (this.ʻ != null) {
                i = this.ʻ.hashCode();
            }
            return hashCode ^ i;
        }

        public String toString() {
            return this.ʽ + ContainerUtils.KEY_VALUE_DELIMITER + this.ʻ;
        }

        public d<K, V> ˏ() {
            d<K, V> dVar;
            for (d<K, V> dVar2 = this.ॱ; dVar2 != null; dVar2 = dVar2.ॱ) {
                dVar = dVar2;
            }
            return dVar;
        }

        public d<K, V> ˊ() {
            d<K, V> dVar;
            for (d<K, V> dVar2 = this.ˊ; dVar2 != null; dVar2 = dVar2.ˊ) {
                dVar = dVar2;
            }
            return dVar;
        }
    }

    class e extends AbstractSet<Entry<K, V>> {
        final /* synthetic */ atz ˊ;

        e(atz o_atz) {
            this.ˊ = o_atz;
        }

        public int size() {
            return this.ˊ.ˏ;
        }

        public Iterator<Entry<K, V>> iterator() {
            return new b<Entry<K, V>>(this) {
                final /* synthetic */ e ॱ;

                {
                    this.ॱ = r2;
                    atz o_atz = r2.ˊ;
                }

                public /* synthetic */ Object next() {
                    return ˎ();
                }

                public Entry<K, V> ˎ() {
                    return ˋ();
                }
            };
        }

        public boolean contains(Object obj) {
            return (obj instanceof Entry) && this.ˊ.ˊ((Entry) obj) != null;
        }

        public boolean remove(Object obj) {
            if (!(obj instanceof Entry)) {
                return false;
            }
            d ˊ = this.ˊ.ˊ((Entry) obj);
            if (ˊ == null) {
                return false;
            }
            this.ˊ.ˎ(ˊ, true);
            return true;
        }

        public void clear() {
            this.ˊ.clear();
        }
    }

    public atz() {
        this(ᐝ);
    }

    public atz(Comparator<? super K> comparator) {
        this.ˏ = 0;
        this.ॱ = 0;
        this.ˋ = new d();
        if (comparator == null) {
            comparator = ᐝ;
        }
        this.ˎ = comparator;
    }

    public int size() {
        return this.ˏ;
    }

    public V get(Object obj) {
        d ˎ = ˎ(obj);
        return ˎ != null ? ˎ.ʻ : null;
    }

    public boolean containsKey(Object obj) {
        return ˎ(obj) != null;
    }

    public V put(K k, V v) {
        if (k == null) {
            throw new NullPointerException("key == null");
        }
        d ˎ = ˎ((Object) k, true);
        V v2 = ˎ.ʻ;
        ˎ.ʻ = v;
        return v2;
    }

    public void clear() {
        this.ˊ = null;
        this.ˏ = 0;
        this.ॱ++;
        d dVar = this.ˋ;
        dVar.ˋ = dVar;
        dVar.ˎ = dVar;
    }

    public V remove(Object obj) {
        d ˏ = ˏ(obj);
        return ˏ != null ? ˏ.ʻ : null;
    }

    d<K, V> ˎ(K k, boolean z) {
        int i;
        Comparator comparator = this.ˎ;
        d<K, V> dVar = this.ˊ;
        if (dVar != null) {
            int compareTo;
            Comparable comparable = comparator == ᐝ ? (Comparable) k : null;
            while (true) {
                if (comparable != null) {
                    compareTo = comparable.compareTo(dVar.ʽ);
                } else {
                    compareTo = comparator.compare(k, dVar.ʽ);
                }
                if (compareTo == 0) {
                    return dVar;
                }
                d<K, V> dVar2 = compareTo < 0 ? dVar.ॱ : dVar.ˊ;
                if (dVar2 == null) {
                    break;
                }
                dVar = dVar2;
            }
            int i2 = compareTo;
            d dVar3 = dVar;
            i = i2;
        } else {
            d<K, V> dVar4 = dVar;
            i = 0;
        }
        if (!z) {
            return null;
        }
        d<K, V> dVar5;
        d dVar6 = this.ˋ;
        if (dVar3 != null) {
            dVar5 = new d(dVar3, k, dVar6, dVar6.ˋ);
            if (i < 0) {
                dVar3.ॱ = dVar5;
            } else {
                dVar3.ˊ = dVar5;
            }
            ˏ(dVar3, true);
        } else if (comparator != ᐝ || (k instanceof Comparable)) {
            dVar5 = new d(dVar3, k, dVar6, dVar6.ˋ);
            this.ˊ = dVar5;
        } else {
            throw new ClassCastException(k.getClass().getName() + " is not Comparable");
        }
        this.ˏ++;
        this.ॱ++;
        return dVar5;
    }

    d<K, V> ˎ(Object obj) {
        d<K, V> dVar = null;
        if (obj != null) {
            try {
                dVar = ˎ(obj, false);
            } catch (ClassCastException e) {
            }
        }
        return dVar;
    }

    d<K, V> ˊ(Entry<?, ?> entry) {
        d<K, V> ˎ = ˎ(entry.getKey());
        Object obj = (ˎ == null || !ॱ(ˎ.ʻ, entry.getValue())) ? null : 1;
        return obj != null ? ˎ : null;
    }

    private boolean ॱ(Object obj, Object obj2) {
        return obj == obj2 || (obj != null && obj.equals(obj2));
    }

    void ˎ(d<K, V> dVar, boolean z) {
        int i = 0;
        if (z) {
            dVar.ˋ.ˎ = dVar.ˎ;
            dVar.ˎ.ˋ = dVar.ˋ;
        }
        d dVar2 = dVar.ॱ;
        d dVar3 = dVar.ˊ;
        d dVar4 = dVar.ˏ;
        if (dVar2 == null || dVar3 == null) {
            if (dVar2 != null) {
                ॱ((d) dVar, dVar2);
                dVar.ॱ = null;
            } else if (dVar3 != null) {
                ॱ((d) dVar, dVar3);
                dVar.ˊ = null;
            } else {
                ॱ((d) dVar, null);
            }
            ˏ(dVar4, false);
            this.ˏ--;
            this.ॱ++;
            return;
        }
        int i2;
        dVar2 = dVar2.ॱॱ > dVar3.ॱॱ ? dVar2.ˊ() : dVar3.ˏ();
        ˎ(dVar2, false);
        dVar4 = dVar.ॱ;
        if (dVar4 != null) {
            i2 = dVar4.ॱॱ;
            dVar2.ॱ = dVar4;
            dVar4.ˏ = dVar2;
            dVar.ॱ = null;
        } else {
            i2 = 0;
        }
        dVar4 = dVar.ˊ;
        if (dVar4 != null) {
            i = dVar4.ॱॱ;
            dVar2.ˊ = dVar4;
            dVar4.ˏ = dVar2;
            dVar.ˊ = null;
        }
        dVar2.ॱॱ = Math.max(i2, i) + 1;
        ॱ((d) dVar, dVar2);
    }

    d<K, V> ˏ(Object obj) {
        d ˎ = ˎ(obj);
        if (ˎ != null) {
            ˎ(ˎ, true);
        }
        return ˎ;
    }

    private void ॱ(d<K, V> dVar, d<K, V> dVar2) {
        d dVar3 = dVar.ˏ;
        dVar.ˏ = null;
        if (dVar2 != null) {
            dVar2.ˏ = dVar3;
        }
        if (dVar3 == null) {
            this.ˊ = dVar2;
        } else if (dVar3.ॱ == dVar) {
            dVar3.ॱ = dVar2;
        } else if (ॱॱ || dVar3.ˊ == dVar) {
            dVar3.ˊ = dVar2;
        } else {
            throw new AssertionError();
        }
    }

    private void ˏ(d<K, V> dVar, boolean z) {
        d dVar2;
        while (dVar2 != null) {
            int i;
            d dVar3 = dVar2.ॱ;
            d dVar4 = dVar2.ˊ;
            int i2 = dVar3 != null ? dVar3.ॱॱ : 0;
            if (dVar4 != null) {
                i = dVar4.ॱॱ;
            } else {
                i = 0;
            }
            int i3 = i2 - i;
            d dVar5;
            if (i3 == -2) {
                dVar3 = dVar4.ॱ;
                dVar5 = dVar4.ˊ;
                if (dVar5 != null) {
                    i2 = dVar5.ॱॱ;
                } else {
                    i2 = 0;
                }
                if (dVar3 != null) {
                    i = dVar3.ॱॱ;
                } else {
                    i = 0;
                }
                i -= i2;
                if (i == -1 || (i == 0 && !z)) {
                    ˎ(dVar2);
                } else if (ॱॱ || i == 1) {
                    ॱ(dVar4);
                    ˎ(dVar2);
                } else {
                    throw new AssertionError();
                }
                if (z) {
                    return;
                }
            } else if (i3 == 2) {
                dVar4 = dVar3.ॱ;
                dVar5 = dVar3.ˊ;
                i2 = dVar5 != null ? dVar5.ॱॱ : 0;
                if (dVar4 != null) {
                    i = dVar4.ॱॱ;
                } else {
                    i = 0;
                }
                i -= i2;
                if (i == 1 || (i == 0 && !z)) {
                    ॱ(dVar2);
                } else if (ॱॱ || i == -1) {
                    ˎ(dVar3);
                    ॱ(dVar2);
                } else {
                    throw new AssertionError();
                }
                if (z) {
                    return;
                }
            } else if (i3 == 0) {
                dVar2.ॱॱ = i2 + 1;
                if (z) {
                    return;
                }
            } else if (ॱॱ || i3 == -1 || i3 == 1) {
                dVar2.ॱॱ = Math.max(i2, i) + 1;
                if (!z) {
                    return;
                }
            } else {
                throw new AssertionError();
            }
            dVar2 = dVar2.ˏ;
        }
    }

    private void ˎ(d<K, V> dVar) {
        int i;
        int i2 = 0;
        d dVar2 = dVar.ॱ;
        d dVar3 = dVar.ˊ;
        d dVar4 = dVar3.ॱ;
        d dVar5 = dVar3.ˊ;
        dVar.ˊ = dVar4;
        if (dVar4 != null) {
            dVar4.ˏ = dVar;
        }
        ॱ((d) dVar, dVar3);
        dVar3.ॱ = dVar;
        dVar.ˏ = dVar3;
        if (dVar2 != null) {
            i = dVar2.ॱॱ;
        } else {
            i = 0;
        }
        dVar.ॱॱ = Math.max(i, dVar4 != null ? dVar4.ॱॱ : 0) + 1;
        int i3 = dVar.ॱॱ;
        if (dVar5 != null) {
            i2 = dVar5.ॱॱ;
        }
        dVar3.ॱॱ = Math.max(i3, i2) + 1;
    }

    private void ॱ(d<K, V> dVar) {
        int i;
        int i2 = 0;
        d dVar2 = dVar.ॱ;
        d dVar3 = dVar.ˊ;
        d dVar4 = dVar2.ॱ;
        d dVar5 = dVar2.ˊ;
        dVar.ॱ = dVar5;
        if (dVar5 != null) {
            dVar5.ˏ = dVar;
        }
        ॱ((d) dVar, dVar2);
        dVar2.ˊ = dVar;
        dVar.ˏ = dVar2;
        if (dVar3 != null) {
            i = dVar3.ॱॱ;
        } else {
            i = 0;
        }
        dVar.ॱॱ = Math.max(i, dVar5 != null ? dVar5.ॱॱ : 0) + 1;
        int i3 = dVar.ॱॱ;
        if (dVar4 != null) {
            i2 = dVar4.ॱॱ;
        }
        dVar2.ॱॱ = Math.max(i3, i2) + 1;
    }

    public Set<Entry<K, V>> entrySet() {
        Set set = this.ʻ;
        if (set != null) {
            return set;
        }
        Set<Entry<K, V>> eVar = new e(this);
        this.ʻ = eVar;
        return eVar;
    }

    public Set<K> keySet() {
        Set set = this.ʼ;
        if (set != null) {
            return set;
        }
        Set<K> cVar = new c(this);
        this.ʼ = cVar;
        return cVar;
    }

    private Object writeReplace() throws ObjectStreamException {
        return new LinkedHashMap(this);
    }
}
